package org.wxd.category.engine;

import com.alibaba.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wxd.category.api.dto.CategoryAddRequest;
import org.wxd.category.api.dto.CategoryRecord;
import org.springframework.transaction.annotation.Transactional;
import org.wxd.category.api.CategoryService;
import org.wxd.category.spi.Category;
import org.wxd.category.spi.CategoryOperations;

import javax.annotation.Resource;

/**
 * Created by wangxd on 2015/11/12.
 */
@Transactional
@Service(version = "1.0.0")
public class CategoryServiceImpl implements CategoryService {
    private static Logger logger = LoggerFactory.getLogger(CategoryServiceImpl.class);
    @Resource
    private CategoryOperations catOps;

    public CategoryRecord addCategory(CategoryAddRequest request) {
        return CategoryHelper.asCategoryRecord(
                catOps.store(Category.newBuilder().name(request.name()).moreInfo(request.moreInfo()).parentId(request.pId()).build())
        );
    }
}
